package com.oa.jixiao.controller;


import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.oa.jixiao.biz.AttendanceBiz;
import com.oa.jixiao.entity.Attendance;
import com.oa.jixiao.entity.EmpVO;
import com.oa.jixiao.entity.ListVO;
import com.oa.login.biz.NameUtil;
import com.oa.xinxi.entity.News;

@Controller
@RequestMapping("/kaoqin")
public class QueryController {
	
	
	@Resource
	private NameUtil util;
	
	@Resource
	private AttendanceBiz atdBiz;
	
	@RequestMapping("/query")
	public String query(){
		return "/jixiao/query";
	}
	
	@ResponseBody
	@RequestMapping("/list1")
	public List<EmpVO> list1(String startime,String endtime)throws Exception{
		String startime1=startime.replace("/", "-");
		String endtime1=endtime.replace("/", "-");
		SimpleDateFormat sf=new SimpleDateFormat("MM-dd-yyyy");
		SimpleDateFormat sf1=new SimpleDateFormat("yyyy-MM-dd");
		EmpVO empVo=new EmpVO(sf1.format(sf.parse(startime1)),sf1.format(sf.parse(endtime1)));
		List<Attendance> list=atdBiz.findAllByTiME(empVo);
		List<EmpVO> empList=new ArrayList<>();
		for(Attendance atd:list){
			EmpVO e=new EmpVO();
			e.setNumber(atd.getEmpNum());
			e.setStartime(atd.getAtdAm());
			e.setEndtime(atd.getAtdPm());
			e.setAtdDate(atd.getAtdDate());
			e.setUsername(util.getName(atd.getEmpNum()));
			empList.add(e);
		}
		return empList;
	}
	
	
//	@ResponseBody
//	@RequestMapping("/list2")
//	public ListVO list2(String empNum,String startime,String endtime,@RequestParam(required=true,defaultValue="1") Integer page) throws Exception{
//		PageHelper.startPage(page, 10);
//		String startime1=startime.replace("/", "-");
//		String endtime1=endtime.replace("/", "-");
//		SimpleDateFormat sf=new SimpleDateFormat("MM-dd-yyyy");
//		SimpleDateFormat sf1=new SimpleDateFormat("yyyy-MM-dd");
//		EmpVO empVo=new EmpVO(sf1.format(sf.parse(startime1)),sf1.format(sf.parse(endtime1)));
//		empVo.setNumber(empNum);
//		List<Attendance> list=atdBiz.findAllByTiMEAndNum(empVo);
//		List<EmpVO> empList=new ArrayList<>();
//		for(Attendance atd:list){
//			EmpVO e=new EmpVO();
//			e.setNumber(atd.getEmpNum());
//			e.setStartime(atd.getAtdAm());
//			e.setEndtime(atd.getAtdPm());
//			e.setAtdDate(atd.getAtdDate());
//			e.setUsername(util.getName(atd.getEmpNum()));
//			empList.add(e);
//		}
//		PageInfo<Attendance> p=new PageInfo<Attendance>(list);
//		ListVO listVO=new ListVO();
//		listVO.setList(empList);
//		listVO.setPage(p);
//		return listVO;
//	}
//	
	

	
	
	@ResponseBody
	@RequestMapping("/list2")
	public List<EmpVO> list2(String empNum,String startime,String endtime) throws Exception{
		String startime1=startime.replace("/", "-");
		String endtime1=endtime.replace("/", "-");
		SimpleDateFormat sf=new SimpleDateFormat("MM-dd-yyyy");
		SimpleDateFormat sf1=new SimpleDateFormat("yyyy-MM-dd");
		EmpVO empVo=new EmpVO(sf1.format(sf.parse(startime1)),sf1.format(sf.parse(endtime1)));
		empVo.setNumber(empNum);
		List<Attendance> list=atdBiz.findAllByTiMEAndNum(empVo);
		List<EmpVO> empList=new ArrayList<>();
		for(Attendance atd:list){
			EmpVO e=new EmpVO();
			e.setNumber(atd.getEmpNum());
			e.setStartime(atd.getAtdAm());
			e.setEndtime(atd.getAtdPm());
			e.setAtdDate(atd.getAtdDate());
			e.setUsername(util.getName(atd.getEmpNum()));
			empList.add(e);
		}
		return empList;
	}
	
}
